/**

 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true,
  },
  {
    path: '/personalCenter',
    hidden: true,
    component: Layout,
    redirect: 'noRedirect',
    children: [
      {
        path: 'index',
        name: 'personalCenter',
        component: () => import('@/views/personalCenter/index'),
        meta: {
          title: '个人中心',
          icon: 'marker',
        },
      },
    ],
  },

  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
]

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index/index'),
        meta: {
          title: '首页',
          icon: 'home',
          affix: true,
        },
      },
    ],
  },

  {
    path: '/personnelManagement',
    component: Layout,
    redirect: 'noRedirect',
    name: 'PersonnelManagement',
    meta: { title: '用户管理', icon: 'users', permissions: ['admin'] },
    children: [
      {
        path: 'userManagement',
        name: 'UserManagement',
        component: () =>
          import('@/views/personnelManagement/userManagement/index'),
        meta: { icon: 'users', title: '用户管理' },
      },
    ],
  },

  {
    path: '/basicInformationManagement',
    component: Layout,
    redirect: 'noRedirect',
    name: 'basicInformationManagement',
    meta: { title: '基本信息管理', icon: 'boxes', permissions: ['admin'] },
    children: [
      {
        path: 'departmentManagement',
        name: 'departmentManagement',
        component: () =>
          import('@/views/basicInformationManagement/department/index'),
        meta: { title: '院系管理' },
      },
      {
        path: 'majorManagement',
        name: 'majorManagement',
        component: () =>
          import('@/views/basicInformationManagement/major/index'),
        meta: { title: '专业管理' },
      },
      {
        path: 'clazzManagement',
        name: 'clazzManagement',
        component: () =>
          import('@/views/basicInformationManagement/clazz/index'),
        meta: { title: '班级管理' },
        children: [
          {
            hidden: true,
            path: 'clazzuserManagement',
            name: 'clazzuserManagement',
            component: () =>
              import('@/views/basicInformationManagement/clazz/user'),
            meta: { title: '班级人员管理' },
          },
        ],
      },

      {
        path: 'courseManagement',
        name: 'courseManagement',
        component: () =>
          import('@/views/basicInformationManagement/course/index'),
        meta: { title: '课程管理' },
      },
    ],
  },

  {
    path: '/questionManagement',
    component: Layout,
    redirect: 'noRedirect',
    name: 'questionManagement',
    meta: {
      title: '题库管理',
      icon: 'align-justify',
      permissions: ['teacher'],
    },
    children: [
      {
        path: 'index',
        name: 'questionManagementindex',
        component: () => import('@/views/questionManagement/index'),
        meta: { icon: 'align-justify', title: '题库管理' },
      },
    ],
  },

  {
    path: '/paperManagement',
    component: Layout,
    redirect: 'noRedirect',
    name: 'paperManagement',
    meta: { title: '考卷管理', icon: 'users', permissions: ['teacher'] },
    children: [
      {
        path: 'index',
        name: 'paperManagementindex',
        component: () => import('@/views/paperManagement/index'),
        meta: { icon: 'atlas', title: '考卷管理' },
      },
    ],
  },
  {
    path: '/grade',
    component: Layout,
    redirect: 'noRedirect',
    name: 'grade',
    meta: { title: '评阅试卷', icon: 'users', permissions: ['teacher'] },
    children: [
      {
        path: 'index',
        name: 'grade',
        component: () => import('@/views/grade/index'),
        meta: { icon: 'users', title: '评阅试卷' },
      },
      {
        hidden: true,
        path: 'answerSheetList/:paperId',
        name: 'answerSheetList',
        component: () => import('@/views/grade/answerSheetList'),
        meta: { icon: 'users', title: '答卷列表' },
      },
    ],
  },
  {
    hidden: true,
    path: '/gradeAnswerSheet/:id',
    name: 'gradeAnswerSheet',
    component: () => import('@/views/grade/gradeAnswerSheet'),
    meta: { icon: 'users', title: '评阅答卷' },
  },
  {
    hidden: true,
    path: '/editPaper/:id',
    name: 'paperManagementeditPaper',
    component: () => import('@/views/paperManagement/editPaper'),
    meta: { icon: 'users', title: '考卷编辑' },
  },

  {
    path: '/courseList',
    component: Layout,
    redirect: 'noRedirect',
    name: 'courseList',
    meta: {
      title: '课程浏览',
      icon: 'align-justify',
      permissions: ['student'],
    },
    children: [
      {
        path: 'index',
        name: 'courseList',
        component: () => import('@/views/courseList/index'),
        meta: { icon: 'align-justify', title: '课程浏览' },
      },
    ],
  },

  {
    path: '/scoreSearch',
    component: Layout,
    redirect: 'noRedirect',
    name: 'scoreSearch',
    meta: { title: '成绩查询', icon: 'search', permissions: ['student'] },
    children: [
      {
        path: 'index',
        name: 'scoreSearch',
        component: () => import('@/views/scoreSearch/index'),
        meta: { icon: 'search', title: '成绩查询' },
      },
    ],
  },
  {
    hidden: true,
    path: '/testing/:id',
    name: 'test',
    component: () => import('@/views/testting/index'),
    meta: { icon: 'users', title: '考试' },
  },

  {
    hidden: true,
    path: '/error',
    component: EmptyLayout,
    redirect: 'noRedirect',
    name: 'Error',
    meta: { title: '错误页', icon: 'bug' },
    children: [
      {
        path: '401',
        name: 'Error401',
        component: () => import('@/views/401'),
        meta: { title: '401' },
      },
      {
        path: '404',
        name: 'Error404',
        component: () => import('@/views/404'),
        meta: { title: '404' },
      },
    ],
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})

export function resetRouter() {
  location.reload()
}

export default router
